use ndarray::{Array, arr1, OwnedRepr};
use ndarray::prelude::*;

// 阶跃函数
fn step_function(x: usize) -> usize {
    if x > 0 {
        1
    } else {
        0
    }
}

fn step_function_np<D>(x: Array<i32,D>) -> ArrayBase<OwnedRepr<Vec<i32>>, D> where D: Dimension {
    let y = x.iter()
        .copied()
        .map(|item| {
        if item > 0 {
            1
        } else {
            0
        }
    }).collect::<Vec<i32>>();

    array!(y)
}

fn main() {
    let x = array![[1,2,3],[-1,2,0]];
    let y = step_function_np::<Ix2>(x);
    println!("{:?}", y);
}